<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    input{
      display: block;
      width: 300px;
      height: 30px;
      margin-bottom: 10px;
      line-height: 30px;
      padding: 5px;
      border-radius: 4px;
      border: 1px solid #555;
      background-color: #fff;
    }
  </style>
</head>
<body>
  <input class="myInput" >
  <input class="myInput">
  <input class="myInput">
  <input class="myInput">
  <input class="myInput">  
</body>
<script>
  // 一组文本框，要求让每一个文本框在自己输入的时候，背景显示灰色，其他文本框显示白色。
  var myInput = document.getElementsByClassName("myInput");
  for(var i = 0; i < myInput.length; i++){
    var inputItem = myInput[i];
    inputItem.index = i;
    inputItem.onfocus = function(){
      for(var j = 0; j < myInput.length; j++){
        myInput[j].style.backgroundColor = '#fff';
      }
      myInput[this.index].style.backgroundColor = 'gray';
    }
  }
</script>
</html>